#include "silicoolcamerafactory.h"
#include "baslercamera.h"
#include "hikcammera.h"

SilicoolCamera *SilicoolcameraFactory::createSilicoolcamera(CameraType type, QString cameraName)
{
    qInfo("create camera: %d", type);
    SilicoolCamera * camera;
    if (type == CameraType::HIK) {
        camera = new HIKCamera();
    } else if (type == CameraType::BASLER) {
        camera = new BaslerCamera();
    }
    camera->setCameraName(cameraName);
    this->silicoolCameraList.push_back(camera);
    return camera;
}

void SilicoolcameraFactory::stopAllSilicoolCamera()
{
    qInfo("Stop all silicool camera");
    for (SilicoolCamera *camera : silicoolCameraList)
    {
        camera->SCCameraStop();
    }
}

QImage SilicoolcameraFactory::getImage(QString cameraName, bool &ret)
{
    QImage image;
    ret = false;
    for (SilicoolCamera *camera : silicoolCameraList) {
        qInfo() << "Get camera from silicool camera list" << camera->cameraName();
        if (!camera->cameraName().compare(cameraName)){
            SilicoolCamera::SCReturnCode scRet = camera->SCGetImage(image);
            if (scRet == SilicoolCamera::SC_OK) {
                ret = true;
            } else {
                qWarning() << cameraName << " Grab image fail.";
            }
        }
    }
    return image;
}
